<{include file="Public/top.html" }>
</head>
<body>
<div id="warpper">
    <div class="content">
        <div class="location">积分抽奖</div>
        <div class="ui-tab">
            <ul>
                <li class="tab-item <{if $action eq dialLottery}>selected<{/if}>"><a href="<{U('PointLottery/dialLottery')}>" onclick="LayerShow();">奖项配置</a></li>
                <li class="tab-item <{if $action eq setPage}>selected<{/if}>"><a href="<{U('PointLottery/setPage')}>" onclick="LayerShow();">功能配置</a></li>
                <li class="tab-item <{if $action eq prizeLog}>selected<{/if}>"><a href="<{U('PointLottery/prizeLog')}>&type=3" onclick="LayerShow();">中奖记录</a></li>
            </ul>
        </div>
        <div class="SignInBOx">
            <form action="" class="ui-form" id="form">
                <div class="ui-form-item" style="height:auto;">
                    <dl>
                        <label class="ui-label">功能开关：</label>
                        <input type="button" class="<{if $data.POINT_LOTTERY_DIAL_SWITCH==1}>switches2<{else}>switches1<{/if}>" value="<{if $data.POINT_LOTTERY_DIAL_SWITCH==1}>启用<{else}>停用<{/if}>" id="switches">
                        <input type="hidden" value="<{if $data.POINT_LOTTERY_DIAL_SWITCH==1}>1<{else}>0<{/if}>" id="switch" name="switch"/>
                    </dl>
                    <dl>
                        <label class="ui-label">消耗积分：</label>
                        <input type="text" class="ui-text" placeholder="每次抽奖消耗积分数" name="basePoint" id="basePoint" value="<{$data.POINT_LOTTERY_DIAL_BASE_POINT}>" required/>
                    </dl>
                    <dl>
                        <label class="ui-label">规则说明：</label>
                        <textarea class="ui-textarea" style="width:220px; height:236px;" name="rule" placeholder="请输入活动规则，换行以‘$’结尾。例如：1、每累计签到7天可获得一次抽奖机会。$2、每月满签可额外获得一次抽奖机会。$"><{$data.POINT_LOTTERY_DIAL_RULE}></textarea>
                    </dl>
                </div>
                <div class="ui-form-item" style="height:auto; vertical-align:top;">
                    <label class="ui-label">积分抽奖底图：</label>
                    <span class="picture_box picture_640">
                        <div class="a-imgBox" id="imgBox1" <{if $data.POINT_LOTTERY_DIAL_PAGE_IMG}> style="display:block;" <{else}> style="display:none;" <{/if}>>
                            <a href="javascript:void(0);" class="a-close" onclick="removeElement('imgBox1','baseImg1')"></a>
                            <img src="<{$data.POINT_LOTTERY_DIAL_PAGE_IMG}>" width="215" height="340" id="baseImg1"/>
                            <input type="hidden" name="pagePic" id="basePic1" value="<{$data.POINT_LOTTERY_DIAL_PAGE_IMG}>" />
                        </div>
                        <div style="margin-top:90px;">
                            <a href="javascript:void(0);" class="a-upload">
                                <input type="file" name="file" id="upload1" onclick="upload(1)">
                            </a>
                            <i>上传图片</i>
                            <i>640*1007</i>
                        </div>
                    </span>
                    <label class="ui-label mll00">奖品说明底图：</label>
                    <span class="picture_box picture_640">
                        <div class="a-imgBox" id="imgBox2" <{if $data.POINT_LOTTERY_DIAL_PRIZE_IMG}> style="display:block;" <{else}> style="display:none;" <{/if}>>
                            <a href="javascript:void(0);" class="a-close" onclick="removeElement('imgBox2','baseImg2')"></a>
                            <img src="<{$data.POINT_LOTTERY_DIAL_PRIZE_IMG}>" width="215" height="340" id="baseImg2"/>
                            <input type="hidden" name="prizePic" id="basePic2" value="<{$data.POINT_LOTTERY_DIAL_PRIZE_IMG}>" />
                        </div>
                        <div style="margin-top:90px;">
                            <a href="javascript:void(0);" class="a-upload">
                                <input type="file" name="file" id="upload2" onclick="upload(2)">
                            </a>
                            <i>上传图片</i>
                            <i>640*1007</i>
                        </div>
                    </span>
                    <a style="position: absolute;margin-top:310px;margin-left: 10px;color: #2077d1;" href="<{$preStaticUrl}>Admin/czkimg/dialBg.jpg" title="点击下载" download="dialBG.png">素材下载</a>
                </div>
            </form>
        </div>
        <div class="integral_btn-group">
            <input type="button" value="提交" class="ui-button" id="btn"/>
        </div>
    </div>
</div>
<{include file="Public/foot.html" }>
</body>
</html>
<script>
    window.onload = function(){
        $("#switches").click(function(){
            if($(this).hasClass("switches1")){
                $(this).removeClass("switches1");
                $(this).addClass("switches2");
            }
            else if($(this).hasClass("switches2")){
                $(this).removeClass("switches2");
                $(this).addClass("switches1");
            }
            $(this).val($(this).val() == "停用"?"启用":"停用");
            $("#switch").val($(this).val() == "停用"?"0":"1");
        })
    }

    function removeElement(id,src)
    {
        document.getElementById(id).style.display="none";
        //删除图片
        $("#"+src).val('');
    }
    //上传底图
    function upload(i) {
        var uploadPic = $('#upload'+i);
        uploadPic.AjaxFileUpload({
            action: './api.php?m=Api&c=index&a=ajaxUpload&from=IMG_DIAL_ABOUT_BASE',
            onSubmit: function () {
                console.log("开始上传");
            },
            onComplete: function (filename, response) {
                if(parseInt(response.id)>0){
                    layer.msg("上传成功");
                    $('#basePic'+i).val(response.msg);
                    $("#baseImg"+i).attr('src',response.msg);
                    document.getElementById('imgBox'+i).style.display="block";
                }else{
                    console.log(response.msg);
                    layer.msg(response.msg);
                }
            }
        });
    }

    $("#btn").on('click',function () {
        var url = "<{U('PointLottery/savePageSet')}>";
        var param = $("#form").serialize();
        var funSwitch = $("#switch").val(),
                basePoint = $('#basePoint').val();
        if(funSwitch == 1 && (basePoint <= 0) || (!basePoint)){
            layer.msg('请输入消耗积分值');
            return false;
        }

        $.getJSON(url,param,function (data) {
            layer.msg(data.msg);
            if(data.status == 0){
                location.reload();
            }
        });

    });

</script>